home *** CD-ROM | disk | FTP | other *** search
- Path: cafu.fl.net.au!usenet
- From: als@fl.net.au (Andrew Snow)
- Newsgroups: comp.lang.c
- Subject: Re: How to tell if a file exists in C
- Date: Sun, 18 Feb 1996 10:09:44 GMT
- Organization: First Link Internet Services
- Message-ID: <4g8132$mg9@cafu.fl.net.au>
- References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <4eqn9q$dr1@sparcserver.lrz-muenchen.de> <3121db3e.43150046@nntp.ix.netcom.com> <4ftpnk$i74@cafu.fl.net.au> <824493561snz@genesis.demon.co.uk>
- NNTP-Posting-Host: snowville.fl.net.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
-
- >In article <4ftpnk$i74@cafu.fl.net.au> als@fl.net.au "Andrew Snow" writes:
-
- >>How about plain old:
- >>
- >> if(0==access("filename", F_OK))
- >> {
- >> do stuff with file();
- >> }
- >> else
- >> {
- >> error();
- >> }
- >>
- >>This works O.K. under Linux and FreeBSD, and most DOS compilers.
-
- >access() is a specialised function under Unix/POSIX to test permissions
- >against the real user/group ID's. If you don't want to do that specifically
- >you should never use access() (and why on other systems you should avoid it
- >where portability is concerned). stat() is the way to go in that case.
-
- Specialised? well its a part of every single DOS compiler I've ever
- seen.
-
- >However neither of these are as portable as fopen() since that is defined by
- >the C language.
-
- True, however I was only offering access() as a viable alternative.
-
- >>If you want to see if the file is readable as well as exists,
-
- >Can a file be readable yet not exist?
-
- No, but did you really want me to spell it out? You ought to have
- been able to figure it out. Sorry if you couldn't.
-
- ----
- Andrew Snow
- als@fl.net.au
- http://www-als.fl.net.au
-
-